package com.wangjinhai.ribbon;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/8/14.
 * @Modified By:
 */
@Service
public class UserRibbon {
    private static final String USER_URL="http://spring-cloud-server-user/";

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod ="fallbacksayHi")
    public String sayHi( String message){
        return restTemplate.
                getForObject(USER_URL + "sayHi?message="+message,
                        String.class);
    }

    public String fallbacksayHi( String message){
        return String.format("Hi，your message is : %s but request error.",message);
    }
}
